<?php
/**
 * CGroup class file.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.yiiframework.com/
 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

/**
 * CGroup represents information relevant to grouping.
 *
 * When data needs to be grouped according to one or several attributes,
 * we can use Cgroup to represent the grouping information and generate
 * appropriate hyperlinks that can lead to group actions.
 *
 * Cgroup is designed to be used together with {@link CActiveRecord}.
 * When creating a Cgroup instance, you need to specify {@link modelClass}.
 * You can use Cgroup to generate hyperlinks by calling {@link link}.
 * You can also use Cgroup to modify a {@link CDbCriteria} instance by calling {@link applyOrder} so that
 * it can cause the query results to be grouped according to the specified
 * attributes.
 *
 * In order to prevent SQL injection attacks, Cgroup ensures that only valid model attributes
 * can be grouped. This is determined based on {@link modelClass} and {@link attributes}.
 * When {@link attributes} is not set, all attributes belonging to {@link modelClass}
 * can be grouped. When {@link attributes} is set, only those attributes declared in the property
 * can be grouped.
 *
 * By configuring {@link attributes}, one can perform more complex groups that may
 * consist of things like compound attributes (e.g. group based on the combination of
 * first name and last name of users).
 *
 * The property {@link attributes} should be an array of key-value pairs, where the keys
 * represent the attribute names, while the values represent the virtual attribute definitions.
 * For more details, please check the documentation about {@link attributes}.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @version $Id: Cgroup.php 2799 2011-01-01 19:31:13Z qiang.xue $
 * @package system.web
 * @since 1.0.1
 */
class CGroup extends CSort
{

	/**
	 * Modifies the query criteria by changing its {@link CDbCriteria::order} property.
	 * This method will use {@link directions} to determine which columns need to be sorted.
	 * They will be put in the ORDER BY clause. If the criteria already has non-empty {@link CDbCriteria::order} value,
	 * the new value will be appended to it.
	 * @param CDbCriteria $criteria the query criteria
	 */
	public function applyOrder($criteria)
	{
		$order=$this->getOrderBy();
		if(!empty($order))
		{
			if(!empty($criteria->order))
				$criteria->order=$order.', '.$criteria->order;
			else
				$criteria->order=$order;
		}
	}
	

}